﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace TinyCinema.Bussiness.Login
{
    public static class FirstTimeRun
    {
        public static bool Check()
        {
            if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "Setting.xml"))
            {
                XmlDocument Doc = new XmlDocument();
                Doc.Load("Setting.xml");
                var Node = Doc.SelectNodes("TinyCinemaManagementSetting")[0];
                var Server = Node.ChildNodes[0].InnerText;
                bool IsUsingWindowsAuth = false;
                if (Node.ChildNodes[1].InnerText == "True")
                    IsUsingWindowsAuth = true;
                var UserName = Node.ChildNodes[2].InnerText;
                var Password = BussinessBase.RC4.Decrypt("P=h%3m-Ue6q;}^&", Node.ChildNodes[3].InnerText); 

                if (IsUsingWindowsAuth) Data.Execution.SetConnectionProperty(Server, null, null);
                else Data.Execution.SetConnectionProperty(Server, UserName, Password);

                return false;
            }
            else
            {                
                return true;
            }
        }
    }
}
